import java.util.concurrent.locks.Lock;

/**
 * @author wcj
 * @Date 2021/6/9 11:37
 * @Version 1.0
 */
public class TwinsLockTest {

 static final Lock LOCK = new TwinsLock();

 public static void main(String[] args) {

  for (int i = 0; i < 10; i++) {
   Worker worker = new Worker();
   worker.setDaemon(true);
   worker.start();
  }


  for (int i = 0; i < 10; i++) {
   SleepUtils.second(1);
   System.out.println();
  }

 }

 static class Worker extends Thread {
  @Override
  public void run() {
   while (true) {
    LOCK.lock();
    try {
     SleepUtils.second(1);
     System.out.println(Thread.currentThread().getName());
     SleepUtils.second(1);
    } finally {
     LOCK.unlock();
    }
   }
  }
 }
}
